﻿using AutoMapper;
using DevWeb.Biztalk.DeploymentSettings.Data.CodeFirst;
using DevWeb.Biztalk.DeploymentSettings.WebUI.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DevWeb.Biztalk.DeploymentSettings.WebUI.Automapper
{
    public class DomainToEntityProfile : Profile
    {

        public const string ViewModel = "DomainToEntityProfile";

        public override string ProfileName
        {
            get { return ViewModel; }
        }

        public DomainToEntityProfile()
        {
            ///DefaultSettingsViewProfile            
            CreateMap<Data.CodeFirst.DefaultSettingParameter, DefaultSettingsViewModel>()
               .ForSourceMember(s => s.DefaultSettingParameterValues, t => t.Ignore());
            CreateMap<DefaultSettingsViewModel, Data.CodeFirst.DefaultSettingParameter>();
            CreateMap<List<DefaultSettingsViewModel>, List<Data.CodeFirst.DefaultSettingParameter>>();


            ///IntegrationVersionSettingsViewProfile
            CreateMap<Data.CodeFirst.IntegrationVersionParameter, IntegrationVersionSettingsViewModel>();
            CreateMap<IntegrationVersionSettingsViewModel, Data.CodeFirst.IntegrationVersionParameter>();
            
            ///DeploymentLogViewProfile
            CreateMap<Data.CodeFirst.DeploymentLog, DeploymentLogViewModel>()
              .ForSourceMember(s => s.Id, t => t.Ignore())
              .ForMember(x => x.IntegrationVersion, opt => opt.MapFrom(src => src.IntegrationVersion.Version))
              .ForMember(x => x.Environment, opt => opt.MapFrom(src => src.TargetEnvironment.Name))
              .ForMember(x => x.ProductId, opt => opt.MapFrom(src => src.IntegrationVersion.ProductId.ToString()))
              .ForMember(x => x.IntegrationName, opt => opt.MapFrom(src => src.IntegrationVersion.Integration.Name));


            //IntegrationVersionViewProfile

            CreateMap<Data.CodeFirst.IntegrationVersion, IntegrationVersionViewModel>();
            CreateMap<IntegrationVersionViewModel, Data.CodeFirst.IntegrationVersion>();
            CreateMap<IntegrationVersionViewModel, Data.CodeFirst.IntegrationVersion>();
            CreateMap<IQueryable<IntegrationVersionViewModel>, IQueryable<Data.CodeFirst.IntegrationVersion>>();
            CreateMap<IQueryable<IntegrationVersionViewModel>, IQueryable<Data.CodeFirst.IntegrationVersion>>();

            ///IntegrationVersionViewProfile
            CreateMap<Integration, IntegrationViewModel>().ReverseMap();
            CreateMap<IQueryable<IntegrationViewModel>, IQueryable<Integration>>();

            ///TargetEnvironmentViewProfile
            CreateMap<TargetEnvironment, TargetEnvironmentViewModel>().ReverseMap();


          





        }

    }
}